import {createRouter,createWebHashHistory} from 'vue-router'
import store from '../store/index.js'


import hj_router from './hj_router'
import zj_router from './zj_router'
import zlc_router from './zlc_router'
const routes = [
    ...hj_router,
    ...zj_router,
    ...zlc_router
]
const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// 全局路由守卫
router.beforeEach((to, from) => {
    
    if (to.path == '/cart') {
        if (!store.state.user.userInfo) {
            return '/notlogin?target=/cart'
        }
        return true
    }
    return true
})

router.beforeEach((to, from) => {
    
    if (to.path == '/my') {
        if (!store.state.user.userInfo) {
            return '/notlogin?target=/my'
        }
        return true
    }
    return true
})

export default router
